# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/28 19:40 
@Author  : ZhangShenao 
@File    : file_parse_exception.py 
@Desc    : 自定义异常
自定义异常,需要继承Exception类
"""


class FileParseException(Exception):
    def __init__(self, file_path):
        super().__init__()
        self.__file_path = file_path

    def __str__(self):
        return f'parse file error! path is: {self.__file_path}'


def read_file(file_path: str):
    try:
        print(f'read file: {file_path}')
        # 模拟读取文件异常
        raise FileParseException(file_path)
    except FileParseException as e:
        print('read file error! ', e)
    finally:
        print('close file')


# 使用自定义异常
read_file('/tmp/test.txt')
